import { Component, OnInit } from '@angular/core';
import { HttpClient } from "@angular/common/http"
import { Router } from "@angular/router"
 
@Component({
  selector: 'app-comtact-new',
  templateUrl: './comtact-new.component.html',
  styleUrls: ['./comtact-new.component.css']
})
export class ComtactNewComponent implements OnInit {

  fromData = {
    name: '',
    email: '',
    phone: ''
  }

  addContact(){
    console.log('asda')
    this.http.post("http://localhost:3000/contacts",this.fromData)
    .toPromise().then(data=>{
      this.router.navigate(["/comtact"]) //跳转到联系人列表
    }).catch(err=>{
      console.log('新增联系人失败')
    })
  }

  constructor(
    private http: HttpClient,
    private router: Router
  ) { }

  ngOnInit() {
  }

}
